{% load i18n lfs_tags %}

{% if cart_items %}
    <h1 class="first-heading">
        {% trans "Voucher" %}
    </h1>
    <input data="{% url lfs_check_voucher_cart %}"
           type="text"
           id="voucher"
           name="voucher"
           value="{{ voucher_number }}"
           size="30" />

    {% if voucher_number and voucher_message %}
        <span class="voucher-message">
            {{ voucher_message }}
        </span>
    {% endif %}

    <h1 class="title">
        {% trans 'Your Cart' %}
    </h1>

    <form id="cart-form"
          action="{% url lfs.cart.views.refresh_cart %}"
          onsubmit="return false;">

        <table class="lfs-default">
            <tr>
                <th colspan="2">
                    {% trans 'Product' %}
                </th>
                <th class="left"
                    colspan="2">
                    {% trans 'Amount' %}
                </th>
                <th class="number">
                    {% trans 'Net Price' %}
                </th>
                <th class="number">
                    {% trans 'VAT' %}
                </th>
                <th class="number">
                    {% trans 'Total' %}
                </th>
                <th></th>
            </tr>
            {% for cart_item in cart_items %}
                <tr>
                    <td class="image">
                        {% if cart_item.product.get_image.image %}
                            <a href="{{ cart_item.product.get_absolute_url }}">
                                <img src="{{ cart_item.product.get_image.image.url_60x60 }}"
                                     alt="{{ cart_item.product.get_name }}"/>
                            </a>
                        {% endif %}
                    </td>
                    <td>
                        <span class="product-title">
                            <a href="{{ cart_item.product.get_absolute_url }}">
                                {{ cart_item.product.get_name }}
                            </a>
                        </span>
                        {% for property in cart_item.product.get_variant_properties %}
                            <div>
                                {{ property.title }}: {{ property.value }} {{ property.unit|safe }}
                            </div>
                        {% endfor %}

                        {% for property in cart_item.product.get_displayed_properties %}
                            <div>
                                {{ property.title }}: {{ property.value }} {{ property.unit|safe }}
                            </div>
                        {% endfor %}

                        {% if cart_item.product.is_configurable_product %}
                            {% for property in cart_item.obj.get_properties %}
                                <div>
                                    {{ property.title }}: {{ property.value }} {{ property.unit|safe }}
                                    {% if property.obj.is_select_field and property.display_price %}
                                        ({{ property.price|currency:request }})
                                    {% endif %}
                                </div>
                            {% endfor %}
                        {% endif %}

                    </td>
                    <td class="number">
                        <input class="number cart-amount"
                               type="text"
                               name="amount-cart-item_{{ cart_item.obj.id }}"
                               size="6"
                               value="{{ cart_item.quantity }}" />
                    </td>
                    <td>
                        {% if cart_item.product.get_unit %}
                            <span class="product-unit">
                                {{ cart_item.product.get_unit }}
                            </span>
                        {% endif %}
                        {% if cart_item.product.get_active_packing_unit %}
                            <span class="packing-unit">
                                ({{ cart_item.obj|packages }} {{ cart_item.product.get_packing_info.1 }})
                            </span>
                        {% endif %}
                    </td>
                    <td class="number"
                        nowrap="nowrap">
                        {{ cart_item.product_price_net|currency:request }}
                    </td>
                    <td class="number"
                        nowrap="nowrap">
                        {{ cart_item.product_tax|currency:request }}
                    </td>
                    <td class="number"
                        nowrap="nowrap">
                        {{ cart_item.product_price_gross|currency:request }}
                    </td>
                    <td class="right">
                        <a href="{% url lfs_delete_cart_item cart_item.obj.id %}"
                           title="{% trans 'Delete item' %}"
                           class="delete-button delete-cart-item">X</a>
                    </td>
                </tr>
            {% endfor %}
            {% for discount in discounts %}
                <tr id="discounts-display">
                    <td></td>
                    <td class="left">
                        {{ discount.name }}
                    </td>
                    <td class="number">
                        1
                    </td>
                    <td class="number">

                    </td>
                    <td class="number">
                        - {{ discount.price_net|currency:request }}
                    </td>
                    <td class="number">
                        - {{ discount.tax|currency:request }}
                    </td>
                    <td class="number">
                        - {{ discount.price_gross|currency:request }}
                    </td>
                    <td></td>
                </tr>
            {% endfor %}

            {% if display_voucher %}
                <tr id="voucher-display">
                    <td></td>
                    <td class="product-title left">
                        {% trans "Voucher" %}
                    </td>
                    <td class="number">
                        1
                    </td>
                    <td></td>
                    <td class="number">
                        - {{ voucher_value|currency:request }}
                    </td>
                    <td class="number">
                        ({{ voucher_tax|currency:request }})
                    </td>
                    <td class="number">
                        - {{ voucher_value|currency:request }}
                    </td>
                    <td></td>
                </tr>
            {% endif %}

            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td class="left">
                    {% trans 'Country' %}:
                </td>
                <td>
                    <select class="cart-country"
                            name="country">
                        {% for country in countries %}
                            <option {% ifequal country.code selected_country.code  %}selected="selected"{% endifequal %}
                                    value="{{ country.code }}">
                                {{ country.name }}
                            </option>
                        {% endfor %}
                    </select>
                </td>
                <td colspan="2"></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td class="left">
                    {% trans 'Shipping' %}:
                </td>
                <td>
                    <select class="cart-shipping-method"
                            name="shipping_method">
                        {% for shipping_method in shipping_methods %}
                            <option {% ifequal shipping_method.id selected_shipping_method.id  %}selected="selected"{% endifequal %}
                                    value="{{ shipping_method.id }}">
                                {{ shipping_method.name }}
                            </option>
                        {% endfor %}
                    </select>
                </td>
                <td></td>
                <td class="number"
                    nowrap="nowrap">
                    {{ shipping_price|currency:request }}
                </td>
                <td></td>
            </tr>

            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td class="left">
                    {% trans 'Payment' %}:
                </td>
                <td>
                    <select class="cart-payment-method"
                            name="payment_method">
                        {% for payment_method in payment_methods %}
                            <option {% ifequal payment_method.id selected_payment_method.id  %}selected="selected"{% endifequal %}
                                    value="{{ payment_method.id }}">
                                {{ payment_method.name }}
                            </option>
                        {% endfor %}
                    </select>
                </td>
                <td></td>
                <td class="number"
                    nowrap="nowrap">
                    {{ payment_price|currency:request }}
                </td>
                <td></td>
            </tr>

            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td colspan="3"
                    class="total left padding-top">
                    {% trans 'Total' %}:
                </td>
                <td class="total number padding-top"
                    nowrap="nowrap">
                    {{ cart_price|currency:request }}
                </td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td colspan="3"
                    class="discreet left">
                    {% trans 'Inclusive VAT' %}:
                </td>
                <td class="discreet number"
                    nowrap="nowrap">
                    {{ cart_tax|currency:request }}
                </td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td colspan="5"
                    class="discreet left padding-top">
                    {% trans 'Total delivery time' %}: {{ max_delivery_time }}
                </td>
            </tr>
            <tr>
                <td colspan="8">
                    <div class="buttons">
                        <a class="button checkout-button emphasized"
                           href="{% url lfs_checkout_dispatcher %}">
                           {% trans 'Checkout' %}
                        </a>
                        <a class="button shopping-button"
                           href="{{ shopping_url }}">
                            {% trans 'Go on shopping' %}
                        </a>
                    </div>
                </td>
            </tr>
        </table>
    </form>
{% else %}
    <h1 class="title">
        {% trans 'Your Cart is empty' %}
    </h1>
    <a class="button emphasized left"
       href="{{ shopping_url }}">
       {% trans 'Go on shopping' %}
    </a>
{% endif %}
